import 'package:flutter/material.dart';
import 'package:wheel_of_fortune/model/user_address_model.dart';
import 'package:wheel_of_fortune/utils/utils.dart';

import 'check_box.dart';

class DeliveryAdress extends StatefulWidget {
  final left;
  final UserAddressModel data;
  final onSelect;
  final onEdit;
  DeliveryAdress({this.left, this.data, this.onSelect, this.onEdit,Key key}) : super(key: key);

  @override
  _DeliveryAdressState createState() => _DeliveryAdressState();
}

class _DeliveryAdressState extends State<DeliveryAdress> {
  @override
  Widget build(BuildContext context) {
    double w = (Utils.screenWidth - widget.left - 18 - 20 - 20 - 10) / 2.0;
    return Container(
      margin: EdgeInsets.fromLTRB(widget.left - 2, 10, 20, 0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          CheckBoxButton(
            isSelect: widget.data.selectAddress,
            onTap: widget.onSelect,
          ),
          SizedBox(width: 20),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                color: Colors.transparent,
                child: Text(
                  'Delivery Address',
                  style: TextStyle(
                      color: mainColor,
                      fontFamily: 'Avenir Next LT Pro',
                      fontSize: 14.0),
                ),
              ),
              SizedBox(height: 10),
              Row(
                children: [
                  AddressWidget(
                    width: w,
                    title: widget.data.address??'',
                  ),
                  Spacer(),
                  InkWell(
                    onTap: widget.onEdit,
                    child: Container(
                      height: 18,
                      width: w,
                      decoration: BoxDecoration(
                        color: Color(0xFFFFB32C),
                        borderRadius: BorderRadius.circular(17),
                      ),
                      child: Center(
                        child: Text(
                          'Edit',
                          style: TextStyle(
                            color: Color(0xFFFFFFFF),
                            fontSize: 10,
                            fontFamily: 'Avenir Next LT Pro',
                            fontWeight: FontWeight.w300,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              SizedBox(height: 10),
              Row(
                children: [
                  AddressWidget(
                    width: w,
                    title: widget.data.cityName??'',
                  ),
                  Spacer(),
                  AddressWidget(
                    width: w,
                    title: widget.data.provinceName??'',
                  ),
                ],
              ),
            ],
          )),
        ],
      ),
    );
  }
}

class AddressWidget extends StatelessWidget {
  final color;
  final title;
  final width;
  const AddressWidget(
      {this.width, this.title = '', this.color = mainColor, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: this.width,
      height: 18,
      padding: EdgeInsets.fromLTRB(3, 1, 1, 0),
      decoration: BoxDecoration(
        color: whiteColor,
        border: Border.all(width: 1, color: mainColor),
        borderRadius: BorderRadius.circular(3.0),
      ),
      child: Text(
        this.title,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(
          fontFamily: 'Avenir Next LT Pro',
          fontSize: 10.0,
          fontWeight: FontWeight.w400,
          color: this.color,
        ),
      ),
    );
  }
}
